<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <script type="text/javascript" src="../script/config.js"></script>
    <script type="text/javascript" src="../script/api.js"></script>
    <style>
        header{ background-color: #f16c3c; line-height: 42px; height: 42px; position: relative;z-index:999;padding-top:22px;}
        header b{ width: 42px; height: 42px; display: inline-block; position: relative; z-index: 9999; background: url() no-repeat center; background-size: 70% auto;  }
        header b.ic-back{ background-image: url(../image/back.png);background-size:25px 25px;}
        header b.ic-check{ background-image: url(../image/ic-check.png); float: right;}
        header .title{ position: absolute; left: 0; bottom: 0; right: 0;  text-align: center; font-size: 18px;color:white;}
        #foot{
          position:relative;;
          margin:10px;
          width:90%;
          height:40px;
          bottom:0;
          left:0;
          font-size:18px;
        }
        .foot_sure{
          margin:0 auto;
          text-align:center;
          line-height:40px;
          width:66%;
          height:40px;
          background-color:#f16c3c;
          color:white;
          border-radius:10px;
        }
        /*.foot_cancle{
          padding-left:17%;
          padding-right:17%;
          padding-top:10px;
          padding-bottom:10px;
          background-color:#f16c3c;
          color:white;
          border-radius:10px;
        }*/
        /*.scheduling_a{
          margin:1.5rem;
          height:150px;
        }
        .scheduling_a_id_a{
          width:100%;
          height:40px;
          font-size:16px;
        }

        .scheduling_id{
            width:100%;
          color:#f16c3c;
        }
        .scheduling_name{
          height:30px;
          margin-top:10px;
          line-height:30px;
        }
        .scheduling_name,.scheduling_address,.scheduling_phone{
          line-height:30px;
        }
        .scheduling_line{
          height:0;
          width:100%;
          border-top:1px solid #d2d2d2;
          margin-top:10px;
        }*/
    </style>
</head>
<body>
    <div id="wrap" class="flex-wrap flex-vertical" >
        <header class="border-b" >
            <b tapmode="hover" onclick="api.closeWin();" class="ic-back"></b>
            <div class="title"></div>
            <b tapmode="hover" onclick="funActionSheet();"  class="ic-check"></b>
        </header>
        <div id="main" class="flex-con" >

        </div>
        <!-- <div id="foot">
            <div tapmode="hover" class="foot_sure" id="foot_sure">事故出险</div>
        </div> -->
    </div>
</body>
</html>
<script type="text/javascript" src="../script/jquery-3.2.1.min.js"></script>
<!-- <script type="text/javascript" src="../script/up_check.js"></script> -->
<script type="text/javascript">
    apiready = function(){
      api.addEventListener({
                            name:'viewappear'
                        }, function(ret, err){
                           api.setScreenOrientation({
                            orientation: 'portrait_up'
                        });
                        });
      $api.text( $api.dom(".title"),api.pageParam.name);
if(api.pageParam.name=="货物交付"){
        api.openFrame({
            name: 'scheduling_z',
            url: './scheduling_z.html',
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight,
                w: api.winWidth,
                h: $api.dom('#main').offsetHeight
            }
});
}
var user = $api.getStorage('user');
var lorry_id=user.lorryid;
// $api.addEvt($api.dom("#foot_sure"),'click',function(){
//   api.confirm({
//     title: '事故出险',
//     msg: '事故出险上报',
//     buttons: ['确定', '取消']
// }, function(ret, err) {
//     var index = ret.buttonIndex;
//     if(index==1){
//
//            var bMap = api.require('bMap');
//            bMap.getLocation({
//                accuracy: '10m',
//                autoStop: false,
//                filter: 1
//            }, function(msg, err1) {
//                if (msg.status) {
//                  $api.post(url+'app.php/change_orders_status2',{
//                   body:{
//                        lorryid:lorry_id,
//                        longitude:msg.lon,
//                        latitude:msg.lat,
//                        }
//                   },function(ret){
//                     if(ret.result==0){
//                       api.toast({
//                          msg:'已经上报物流公司',
//                          duration: 2000,
//                         location: 'middle'
//                       });
//                       // api.closeToWin({
//                       //   name:'main'
//                       // });
//                       setTimeout("api.closeToWin({name:'main'})",2000);
//                      }else{
//                 api.toast({
//                    msg:'上报失败',
//                    duration: 2000,
//                   location: 'middle'
//                 });
//               }
//
//           },'json');
//                } else {
//                    // alert(err.code);
//
//                }
//            });
//
//
//    }
// });
//
// });
}
var check=function(id,time){
  $api.post(url+'app.php/check',{
        body:{lorryid:id,
              time:time,}
       },function(ret){
        if(ret.result==4){
          alert(ret.desc);
          api.openWin({
            name: 'index',
            url:  '../index.html',
          });
           setTimeout("api.closeWin({name:'main'})",650);
           $api.rmStorage('password');
           var key = 'user';
           var user = {};
           var aa=$api.getStorage(key);
           user.lorryid=aa.lorryid;
            user.telephone=aa.telephone;
           user.flag= aa.flag
           user.pass= '';
           $api.setStorage(key, user);
           api.alert({
             title: '提示消息',
             msg: ret.desc,
             buttons: ['确定']
           });
         }else{
          //  alert(ret.desc);
         }
       });
}


function funActionSheet(){
  var user = $api.getStorage('user');
  var lorry_id=user.lorryid;
  api.actionSheet({
    cancelTitle: '取消',
    buttons: ['事故出险']
}, function(ret, err) {
    var index = ret.buttonIndex;

    if(index==1){
      api.confirm({
        title: '事故出险',
        msg: '事故出险上报',
        buttons: ['确定', '取消']
    }, function(ret, err) {
        var index = ret.buttonIndex;
        if(index==1){
               var bMap = api.require('bMap');
               bMap.getLocationServices(function(ret2, err) {
               if (ret2.enable) {
               bMap.getLocation({
                   accuracy: '100m',
                   autoStop: true,
                   filter: 1
               }, function(msg, err1) {
                   if (msg.status) {
                     $api.post(url+'app.php/change_orders_status2',{
                      body:{
                           lorryid:lorry_id,
                           longitude:msg.lon,
                           latitude:msg.lat
                           }
                      },function(ret){
                        if(ret.result==0){
                          api.toast({
                             msg:ret.desc,
                             duration: 2000,
                            location: 'middle'
                          });
                          // api.closeToWin({
                          //   name:'main'
                          // });
                          setTimeout("api.closeToWin({name:'main'})",2000);
                         }else{
                    api.toast({
                       msg:ret.desc,
                       duration: 2000,
                      location: 'middle'
                    });
                  }

              },'json');
                   } else {
                       // alert(err.code);

                   }
               });
}else{
  alert("您现在有待交付清单,司机还在运送中,请开启定位");
  var mySettingInfo = api.require('mySettingInfo');
  mySettingInfo.settingInt({
  'index': 2
  }, function(ret, err) {
  alert(JSON.stringify(ret));
  });
}
});

       }
    });
    }
});
}
</script>
